package task03.code0301;

class CountChar {
    public static void main(String[] args) {
        String str = "ABCD123!@#$%ab";
        count(str);
    }

    static void count(String str) {
        char[] charArray = str.toCharArray();
        String digit = "";
        int digitCount = 0;
        String upper = "";
        int upperCount = 0;
        String lower = "";
        int lowerCount = 0;
        String other = "";
        int otherCount = 0;
        for (char ch : charArray) {
            if (Character.isUpperCase(ch)) {
                upperCount++;
                upper += Character.toString(ch);
            }
            if (Character.isLowerCase(ch)) {
                lowerCount++;
                lower += Character.toString(ch);
            }
            if (Character.isDigit(ch)) {
                digitCount++;
                digit += Character.toString(ch);
            }
            if (!Character.isLetterOrDigit(ch)) {
                otherCount++;
                other += Character.toString(ch);
            }
        }
        System.out.printf("大写字母%d个：\"%s\"；\n小写字母%d个：\"%s\"；\n数字%d个：\"%s\"；\n其他字符%d个：\"%s\"。\n", upperCount, upper,
                lowerCount, lower, digitCount, digit, otherCount, other);
    }
}